package com.dongdongshop.controller;

import com.dongdongshop.constant.HttpResultEnum;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.pojo.item.TbItem;
import com.dongdongshop.service.item.ItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Eayon
 * @Date 2020/4/4 17:38
 */
@RestController
@RequestMapping("item")
public class ItemController {

    private static final Logger log = LoggerFactory.getLogger(ItemController.class);

    @Autowired
    private ItemService itemService;

    /**
     * 根据itemId查询item信息
     * @return
     */
    @GetMapping("/{itemId}")
    public DataResult<TbItem> findItemById(@PathVariable("itemId")Long itemId){
        TbItem item = null;
        try {
            item = itemService.findItemById(itemId);
        }catch (Exception e){
            log.error("根据itemId查询异常",e);
            return new DataResult<TbItem>(HttpResultEnum.ERROR.getCode(),HttpResultEnum.ERROR.getMessage());
        }
        return new DataResult<TbItem>(HttpResultEnum.SUCCESS.getCode(),HttpResultEnum.SUCCESS.getMessage(),item);
    }
}
